extends LabelWithFont

class_name ChatMessage

const MAX_SPEED_CHARACTERS = 20
const MAX_ROLL_ANITIME = 1
var ROLL_ANITIME = MAX_ROLL_ANITIME
const ERASE_ANITIME = 0.2

func _init(_text):

	font_path = "res://fonts/Now FL/Now-SemiBold.otf"
	font_size = 23

	autowrap = true
	size_flags_horizontal = SIZE_EXPAND_FILL
	text = _text
	percent_visible = 0

	var l = text.length()
	if l >= MAX_SPEED_CHARACTERS:
		ROLL_ANITIME = MAX_ROLL_ANITIME
	else:
		ROLL_ANITIME = float(l)/float(MAX_SPEED_CHARACTERS)


func _ready():
	roll_in()

func roll_in():

	var tween =  SDTween.new()
	add_child(tween)
	tween.interpolate_property(self,"percent_visible",0,1,ROLL_ANITIME,Tween.TRANS_LINEAR,Tween.EASE_IN_OUT)
	tween.start()

func erase():
	var tween =  SDTween.new(self, "queue_free")
	add_child(tween)
	tween.interpolate_property(self,"percent_visible",1,0,ERASE_ANITIME,Tween.TRANS_LINEAR,Tween.EASE_IN_OUT)
	tween.start()
